<template>
  <div class="JNPF-common-layout">
    <div class="JNPF-common-layout-center">
      <el-row class="JNPF-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>

          <el-col :span="4">
            <el-form-item label="状态" prop="type">
              <el-select v-model="query.type" placeholder="选择状态">
                <el-option key="" label="所有" value=""/>
                <el-option key="0" label="未审核" value="0"/>
                <el-option key="1" label="已审核" value="1"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="客户名称">
              <el-input v-model="query.customerName" placeholder="客户名称" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="合伙人">
              <el-input v-model="query.partnerUserName" placeholder="合伙人" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="上级合伙人">
              <el-input v-model="query.parentPartnerUserName" placeholder="上级合伙人" clearable/>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
              <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>

            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="JNPF-common-layout-main JNPF-flex-main">
        <div class="JNPF-common-head">
          <div>

          </div>
          <div class="JNPF-common-head-right">
            <el-tooltip effect="dark" content="刷新" placement="top">
              <el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false" @click="reset()"/>
            </el-tooltip>
            <screenfull :isContainer="true"/>
            <el-tooltip effect="dark" content="列设置" placement="top">
              <el-link icon="icon-ym icon-ym-options JNPF-common-head-icon" :underline="false"/>
            </el-tooltip>
          </div>
        </div>
        <JNPF-table v-loading="listLoading" :data="list">
          <el-table-column prop="customerName" label="客户名称" align="left"/>

          <el-table-column prop="amount" label="金额" align="left" width="100px"/>
          <el-table-column label="附件信息" width="120px">
            <template slot-scope="scope">
              <el-image
                  style="width: 50px; height: 50px"
                  :src="item" v-for="item in scope.row.filesList"
                  :preview-src-list="scope.row.filesList">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column prop="partnerUserName" label="合伙人" align="left" width="120px"/>
          <el-table-column prop="partnerPoint" label="合伙人积分" align="left" width="120px"/>

          <el-table-column prop="parentPartnerUserName" label="上级合伙人" align="left" width="120px"/>
          <el-table-column prop="parentUserPoint" label="上级合伙人积分" align="left" width="150px"/>

          <el-table-column label="状态" width="120px">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.type == 0">
                {{ '未审核' }}
              </el-tag>

              <el-tag v-if="scope.row.payType == 1">
                {{ '已审核' }}
              </el-tag>

            </template>
          </el-table-column>

          <el-table-column prop="creatorTime" label="创建时间" align="left" width="150px"/>
          <el-table-column label="操作" fixed="right" width="100">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.type==0" @click="handleDel(scope.row.id)"
                         class="JNPF-table-delBtn">
                审核
              </el-button>
            </template>
          </el-table-column>
        </JNPF-table>
        <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize"
                    @pagination="initData"/>
      </div>
    </div>
    <JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh"/>
    <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download"/>
  </div>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
import JNPFForm from './Form'
import ExportBox from './ExportBox'
import {previewDataInterface} from '@/api/systemData/dataInterface'

export default {
  components: {JNPFForm, ExportBox},
  data() {
    return {
      showAll: false,
      query: {
        customerName: undefined,
        partnerUserName: undefined,
        parentPartnerUserName: undefined,
        type: "0",
      },
      defaultProps: {
        children: 'children',
        label: 'fullName'
      },
      list: [],
      listLoading: true,
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,

        sort: "desc",
        sidx: "",
      },
      formVisible: false,
      exportBoxVisible: false,
      columnList: [
        {prop: 'uuid', label: '关联主表UUID'},
        {prop: 'amount', label: '金额'},
        {prop: 'partnerUserId', label: '合伙人人ID'},
        {prop: 'partnerPoint', label: '合伙人积分'},
        {prop: 'parentPartnerUserId', label: '上级合伙人ID'},
        {prop: 'parentUserPoint', label: '上级合伙人抽佣积分'},

      ],


    }
  },
  computed: {},
  created() {
    this.initData();


  },
  methods: {


    initData() {
      this.listLoading = true;
      let query = {
        ...this.listQuery,
        ...this.query
      };
      request({
        url: `/api/Jiushi/Customerconsultantdetail/GetListAdmin`,
        method: 'get',
        data: query
      }).then(res => {
        this.list = res.data.list.map(item=>{
          if(item.attachmentInfo!=null)
          item.filesList=item.attachmentInfo.split(',')
          return item
        })
        this.total = res.data.pagination.total
        this.listLoading = false
        this.$nextTick(() => {
          this.tableHeight = "100%"
        });
      })
    },
    handleDel(id) {

      this.$confirm('此操作将审核, 是否继续?', '提示', {
        type: 'warning'
      }).then(() => {
        request({
          url: `/api/Jiushi/Customerconsultant/CxamineCreate/${id}`,
          method: 'POST'
        }).then(res => {
          this.$message({
            type: 'success',
            message: res.msg,
            onClose: () => {
              this.initData()
            }
          });
        })
      }).catch(() => {
      });
    },
    addOrUpdateHandle(id, isDetail) {

    },
    exportData() {

    },
    download(data) {

    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,

        sort: "desc",
        sidx: "",
      }
      this.initData()
    },
    refresh(isrRefresh) {
      this.formVisible = false
      if (isrRefresh) this.reset()
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,

        sort: "desc",
        sidx: "",
      }
      this.initData()
    }
  }
}
</script>
